/*
 * CookStew.java
 *
 * Created on March 27, 2007, 4:58 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package ai9hells.pgaibe.chapter2.westworldwithmessaging;

import ai9hells.pgaibe.common.fsm.State;
import ai9hells.pgaibe.common.messaging.Telegram;

/**
 *
 * @author andre.bandarra
 */
public class CookStew extends State<MinersWife>{
    public static final CookStew instance = new CookStew();
    /** Creates a new instance of CookStew */
    private CookStew() {
    }

    public void enter(MinersWife entity) {
        System.out.println(EntityNames.getNameOfEntity(entity.getId())+": Putting the stew in the oven");                                
        MessageDispatcher.INSTANCE.dispatchMessage(
                100,
                entity.getId(), 
                entity.getId(),
                MessageTypes.MSG_STEW_READY,
                null);
        entity.setCooking(true);
    }

    public void execute(MinersWife entity) {
        System.out.println(EntityNames.getNameOfEntity(entity.getId())+": Fussin' over food");                                
    }

    public void exit(MinersWife entity) {
        System.out.println(EntityNames.getNameOfEntity(entity.getId())+": Puttin' the stew on the table");                                
    }

    public boolean onMessage(MinersWife entity, Telegram t) {
        switch(t.getMsg()){
            case MessageTypes.MSG_STEW_READY: 
                System.out.println(EntityNames.getNameOfEntity(entity.getId())+": Stew ready! Let eat!");                                                
                MessageDispatcher.INSTANCE.dispatchMessage(
                        0,
                        entity.getId(),
                        EntityNames.MINER_BOB,
                        MessageTypes.MSG_STEW_READY,
                        null);
                entity.setCooking(false);
                entity.getStateMachine().changeState(DoHouseWork.instance);
                return true;
            default: return false;
        }

    }
    
}
